<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Python IDE</title>
</head>
<script src="lib/axios.min.js"></script>
<script>
    let time = -100;
    let out = "";
    run = function(){
        document.getElementById("button1").disabled = true;
        time = 1;
        document.getElementById("out").value = "正在运行";
        let code = document.getElementById("code");
        let input = document.getElementById("input");
        code.disabled = true;
        input.disabled = true;
        let data = {"code": code.value, "input": input.value};
        console.log(data);
        axios.post("/run", data)
            .then(res=>{
                time = -100;
                out = res.data.out
                document.getElementById("out").value = out;
                code.disabled = false;
                input.disabled = false;
                document.getElementById("button1").disabled = false;
            });
    }
    setInterval(function () {
        if(time > 0){
            if(time%4 == 0) document.getElementById("out").value = "正在运行";
            if(time%4 == 1) document.getElementById("out").value = "正在运行.";
            if(time%4 == 2) document.getElementById("out").value = "正在运行..";
            if(time%4 == 3) document.getElementById("out").value = "正在运行...";
            time ++;
        }
        else {
            document.getElementById("out").value = out;
        }
    }, 500)
</script>
<body>
    <h2>Python IDE</h2>
    <div style="font-size:16px;">
        <label for="code">代码</label><br />
        <textarea style="font-size:26px;" name="code" rows="18" cols="120" id="code" >{{current_code}}</textarea> <br />
        <label for="input">输入</label><br />
        <textarea style="font-size:26px;" rows="6" cols="120" name="input" id="input" >{{current_input}}</textarea> <br />
        <label for="out">运行结果</label>
        <button id="button1" onCLick="run()">运行</button> <br />
        <!-- <p style="font-size:16px;white-space: pre-line;" id="out"></p> -->
        <textarea style="font-size:26px; white-space: pre-line;" disabled rows="6" cols="120" id="out"></textarea> <br />
    </div>
</body>
</html>